package com.ericsson.common.util;

public class FormulaConvert {
    public static final String POINT="_N1_";
    /**
     * 将公式中的特殊符号用数字下划线符号替换
     * @param formula
     * @return
     */
    public static String convertFormula(String formula){
        formula = formula.replaceAll("\\.",POINT).replaceAll(":","_N2_").replaceAll("\\{-\\}","_N5_").replaceAll("\\{/\\}","_N6_").replaceAll("-","_N3_").replaceAll("\\/","_N4_");
        return formula.replaceAll("_N5_","-").replaceAll("_N6_","/").replaceAll("\\[","_N7_").replaceAll("]","_N8_").replaceAll("\\{","_N9_").replaceAll("}","_N10_").replaceAll("=","_N11_").replaceAll("\\|","_N12_").replaceAll(" ","_N13_").replaceAll("@","_N14_").replaceAll("\"","_N15_").replaceAll(",","_N16_").replaceAll("<","_N17_").replaceAll(">","_N18_");
    }

    /**
     * 将被数字下划线替换的公式还原成原来的公式
     * @param formula
     * @return
     */
    public static String restoreFormula(String formula){
        formula = formula.replaceAll(POINT,"\\.").replaceAll("_N2_",":").replaceAll("_N3_","-").replaceAll("_N4_","\\/").replaceAll("_N7_","[").replaceAll("_N8_","]").replaceAll("_N9_","{").replaceAll("_N10_","}").replaceAll("_N11_","=").replaceAll("_N12_","|").replaceAll("_N13_"," ").replaceAll("_N14_","@").replaceAll("_N15_","\"").replaceAll("_N16_",",").replaceAll("_N17_","<").replaceAll("_N18_",">");
        return formula;
    }

}
